EmailSong = {
	container: null,
	error: '',
	
	closeContent: function() {
		$('emailContainer').update('');
		$('emailContainer').hide();
	},
	
	displayEmailContainer: function(song) {
		this.closeContent();
		new Ajax.Request('email.php',
		  {
		    method: 'get',
				parameters: 
					{
						song: song
					},
		    onSuccess: function(transport){
		      var response = transport.responseText;
					$('emailContainer').update(response);
					$('emailContainer').show();
		    }
		  });	
	},
	
	checkValues: function(){
		
		this.error = '';
		
		if ($('song').value == '') {
			this.error += 'First please choose a song.\r\n';
		}
		
		if ($('uname').value == '') {
			this.error += 'Please enter your First Name\r\n';
		}
		
		if ($('uemail').value == '') {
			this.error += 'Please enter your email address\r\n';
		}
		
		if ($('femail').value == '') {
			this.error += "Please enter your friend's email address\r\n";
		}
		
		if ($('fname').value == '') {
			this.error += 'Please enter your Friend Name\r\n';
		}
		return;
	},
	
	SendEmail: function() {
		this.checkValues();
		
		if (this.error == '') {
			new Ajax.Request('tell.php',
			  {
			    method: 'post',
					parameters: 
						{
							song: $('song').value,
							uname: $('uname').value,
							uemail: $('uemail').value,
							femail: $('femail').value,
							fname: $('fname').value
						},
			    onSuccess: function(transport){
			      var response = transport.responseText;
						if (response == 'DONE') {
							$('emailContainer').update('');
							$('emailContainer').hide();
							alert('The email have been succesfully sent.');
						} else {
							alert('An error accoured while trying to send the mail. Please try again.');
						}
			    }
			  });	
		} else {
			//foreach ()this.error
			alert(this.error);
		}
	}
}
	
